//
//  CinemaCell.m
//  MyMovie
//
//  Created by Weiwei on 16/3/4.
//  Copyright © 2016年 bever贝沃汇力 weiwei. All rights reserved.
//

#import "CinemaCell.h"

@interface CinemaCell (){
    
    int i;
}

@end


@implementation CinemaCell



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


-(void)setModel:(CinemaModel *)model{
    _model = model;
    
    self.cinemName.text = _model.cinameName;
    self.cinemAddress.text = _model.address;
    
    
    //拼接字符串
    NSString* string = [NSString stringWithFormat:@"￥%.1f起",[_model.minPrice integerValue]/100.0];
    
    self.cinmePrice.text = string;
    
    
    
    //-------------图片添加方法--------------
    /*
     "feature": {
     "has3D": 1,
     "hasIMAX": 0,
     "hasVIP": 0,
     "hasPark": 1,
     "hasServiceTicket": 1,
     "hasWifi": 0,
     "hasLoveseat": 0,
     "hasFeature4K": 0,
     "hasFeatureDolby": 0,
     "hasFeatureHuge": 0,
     "hasFeature4D": 0
     }
     */
    //但是我们没有十一张图片
    
    
    i = 0;
    //创建一个字典，里面存放key和value,key是feature的key，value是对应的图片数组
    NSDictionary* _imgDic = @{@"has3D":@"v10_18_Feature3D",
          @"hasIMAX":@"v10_18_FeatureIMAX",
          @"hasPark":@"v10_18_park",
          @"hasServiceTicket":@"v10_18_serviceTicket",
          @"hasVIP":@"v10_18_VIP",
          @"hasWifi":@"v10_18_wifi"};
    
    
    //复用问题
    for (UIView * subView in self.contentView.subviews) {
        
        if (subView.frame.size.width == 40) {
            
            [subView removeFromSuperview];
        }
        
    }
    
    
    
    //1.获得当前model里的feature
    NSDictionary* featureDic = self.model.feature;
    //2.获得当前featur里的所有的key
    NSArray* allkeys = [featureDic allKeys];
    
    //3.便利key
    for (NSString* key in allkeys) {
        //利用key取出feature所对应的数据
        NSNumber* number = [featureDic objectForKey:key];
        
        //判断model feature里的key所对应的数据是否为1，而且还要满足在_imagDic里有他的图片
        if ([number isEqualToNumber:@1]&&[[_imgDic allKeys]containsObject:key]) {
            
            UIImageView* imagV = [[UIImageView alloc]initWithFrame:CGRectMake( i*(40+5), 60, 40, 40)];
            i++;
            
            imagV.image = [UIImage imageNamed:[_imgDic objectForKey:key]];
            
            [self.contentView addSubview:imagV];
            
            
            
            
        }
        
        
    }
    
    
}

@end
